


package com.UMLife.me.ui;

import javax.microedition.lcdui.Image;
import com.UMLife.me.action.LoginAction;
import de.enough.polish.ui.Choice;
import de.enough.polish.ui.ChoiceGroup;
import de.enough.polish.ui.ChoiceItem;
import de.enough.polish.ui.Container;
import de.enough.polish.ui.Form;
import de.enough.polish.ui.ImageItem;
import de.enough.polish.ui.Item;
import de.enough.polish.ui.StringItem;
import de.enough.polish.ui.TextField;





public class LoginUI
		extends Form
{
	public LoginUI()
	{
		//#style LoginUI
		super(null);
		
		try
		{
			Image logoImage = Image.createImage("/logo.png");
			this.logo = new ImageItem(null, logoImage, Item.PLAIN, null);
			
		} catch (Exception e)
		{
			// TODO: handle exception
		}
		
		//#style con
		Container con = new Container(true);
		
		//#style LoginNameItem
		StringItem nameItem = new StringItem(null, "账号：", Item.PLAIN);
		//#style LoginNameItem
		StringItem pswItem = new StringItem(null, "密码：", Item.PLAIN);
		//#style textField
		this.name = new TextField(null, "邮箱/昵称", 15, TextField.ANY);
		//#style textField
		this.password = new TextField(null, "", 15, TextField.PASSWORD);
		//#style choice
		this.choice = new ChoiceGroup(null, Choice.MULTIPLE);
		//#style remItem
		ChoiceItem autoLogin = new ChoiceItem("自动登录", null, Item.BUTTON);
		//#style remItem
		ChoiceItem remPsw = new ChoiceItem("记住密码", null, Item.BUTTON);
		this.choice.add(autoLogin);
		this.choice.add(remPsw);
		
		con.add(nameItem);
		con.add(this.name);
		con.add(pswItem);
		con.add(this.password);
		con.add(this.choice);
		
		//杨光添加的事件响应。
		this.append(this.logo);
		this.append(con);
		this.setCommandListener(new LoginAction(this));
		
	}
	
	/**
	 * 获取登录设置：自动登录，记住密码
	 * 
	 * @return
	 */
	public boolean[] getLoginFlag()
	{
		// TODO
		if (this.choice.getSelectedFlags(this.selectFlag) == 2)
		{
			return this.selectFlag;
		}
		else
		{
			return new boolean[2];
		}
	}
	
	/**
	 * 获取账号
	 * 
	 * @return
	 */
	public String getName()
	{
		// TODO
		return this.name.getString();
	}
	
	/**
	 * 获取密码
	 * 
	 * @return
	 */
	public String getPassword()
	{
		// TODO
		return this.password.getString();
	}
	
	private ChoiceGroup	choice;
	
	private ImageItem	logo;
	
	private TextField	name;
	
	private TextField	password;
	
	private boolean[]	selectFlag;
	
}
